<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    div {
        width: 100px;
        height: 100px;
        border: 1px solid black;

    }
</style>

<body>
    <!-- 是真调用16进制颜色假调用256进制颜色 -->
    <script>
        function getRandomColor(flag) {
            if (flag) {
                let str = '#'
                let arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']
                for (let i = 0; i < 6; i++) {
                    let random = Math.floor(Math.random() * arr.length)
                    str += arr[random]
                }
                return str
            }
            else {
                let a = Math.floor(Math.random() * 256)
                let b = Math.floor(Math.random() * 256)
                let c = Math.floor(Math.random() * 256)
                return `rgb(${a},${b},${c})`
            }
        }
        let aaa = getRandomColor(true)
        document.write(`<div style=" background-color:${aaa};">111</div>`)
        document.write(getRandomColor(false))
    </script>
</body>

</html>